package com.zxy.supplier_system.server.repository

import com.zxy.supplier_system.server.entity.GoodsBrandTag
import com.zxy.supplier_system.server.entity.SystemService
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.data.jpa.repository.JpaSpecificationExecutor
import org.springframework.data.jpa.repository.Query
import org.springframework.data.repository.query.Param

interface GoodsBrandTagRepository : JpaRepository<GoodsBrandTag, Int>, JpaSpecificationExecutor<GoodsBrandTag> {

    fun findBySystemService(systemService: SystemService): List<GoodsBrandTag>
    
    fun findByIdAndSystemService(id: Int, systemService: SystemService): GoodsBrandTag?
    
    @Query("SELECT t FROM GoodsBrandTag t JOIN t.systemService s WHERE s = :systemService AND LOWER(t.name) LIKE LOWER(CONCAT('%', :name, '%'))")
    fun searchByName(@Param("name") name: String, @Param("systemService") systemService: SystemService): List<GoodsBrandTag>

    fun existsByNameAndSystemService(name: String, systemService: SystemService): Boolean
}